require "slimekit/version"
require "httparty"

module Slimekit
	# Global configs for "admin" user
	TK_ADMIN_USER = 'my-email@gmail.com'
	TK_ADMIN_TOKEN = '12345ABCD'

	# Example usage:
	# timekit = Timekit.new(TK_ADMIN_USER, TK_ADMIN_TOKEN)
	# tk_user = timekit.create_user(account)
	# someInternalUser.update(tk_token: tk_user.token)

	class Timekit
	  include HTTParty
	  base_uri 'https://api.timekit.io'
	  headers 'Timekit-App' => 'your-app-name'

	  def initialize(user, password)
	    @auth = {username: user, password: password}
	  end

	  def create_user(account)
	    options = {
	      body: {
	        "email" => account.email,
	        "first_name" => account.first_name,
	        "last_name" => account.last_name,
	        "timezone" => "America/Los_Angeles"
	      }.to_json,
	      basic_auth: @auth,
	    }
	    self.class.post('/v2/users/', options)
	  end

	  def create_calendar(account)
	    options = {
	      body: {
	        name: "Appointments",
	        description: "Hold bookings for clients."
	      }.to_json,
	      basic_auth: @auth
	    }
	    self.class.post('/v2/calendars', options)
	  end
	end 
end
